;; -*- coding: utf-8 -*-
;; Fonts setting
(setq cjk-font-size 14)
(setq ansi-font-size 16)
(defun set-font()
  (interactive)
  (create-fontset-from-fontset-spec
   (concat
    "-*-fixed-medium-r-normal-*-*-*-*-*-*-*-fontset-myfontset,"
    (format "ascii:-outline-Consolas-normal-normal-normal-mono-%d-*-*-*-c-*-iso8859-1," ansi-font-size)
    (format "unicode:-microsoft-Microsoft YaHei-normal-normal-normal-*-%d-*-*-*-*-0-iso8859-1," cjk-font-size)
    (format "chinese-gb2312:-microsoft-Microsoft YaHei-normal-normal-normal-*-%d-*-*-*-*-0-iso8859-1," cjk-font-size)
    )))

(defun resize-font-size(offset)
  "decrease font size"
  (if offset
      (progn
	(let ((old-height (frame-height)))
	  (setq cjk-font-size (+ cjk-font-size offset))
	  (setq ansi-font-size (+ ansi-font-size offset))
	  (message "cjk-size:%d pt, ansi-size:%d pt" cjk-font-size ansi-font-size)
	  (set-font)
	  (sit-for .5)))))

(defun increase-font-size()
  "increase font size"
  (interactive)
  (if (< cjk-font-size 48)
      (resize-font-size 2)))
  
(defun decrease-font-size()
  "decrease font size"
  (interactive)
  (if (> cjk-font-size 2)
      (resize-font-size -2)))
  
(defun default-font-size()
  "default font size"
  (interactive)
  (setq cjk-font-size 14)
  (setq ansi-font-size 16)
  (resize-font-size 0))

(if window-system
    (progn
      (set-font)
      (set-frame-font "fontset-myfontset")
      (global-set-key [C-wheel-up] 'increase-font-size)
      (global-set-key [C-wheel-down] 'decrease-font-size)
      (global-set-key (kbd "C--") 'decrease-font-size) ;Ctrl+-
      (global-set-key (kbd "C-0") 'default-font-size)  ;Ctrl+0
      (global-set-key (kbd "C-=") 'increase-font-size) ;Ctrl+=
      ))

(provide 'init-fonts)
